<?php
/**
 */

namespace backend\modules\information\controllers;


use backend\component\BackendBaseController;
use backend\service\CategoryService;
use common\models\info\Category;

class CategoryController extends BackendBaseController
{
    public function actions()
    {
        return [
            "modify" => [
                'class' => "backend\actions\ModifyAction",
                'modelName'=> Category::className()
            ],
            "delete" =>[
                'class' => "backend\actions\DeleteAction",
                'modelName'=> Category::className(),
                'is_physics' => false
            ],
            "switch" => [
                "class" => "backend\actions\SwitchAction",
                "modelName" => Category::className(),
                "field" => "status",
            ],
        ];
    }

    /*
     * 分类列表
     */
    public function actionList() {
        if (\Yii::$app->request->getIsAjax()) {
            return CategoryService::categoryList(\Yii::$app->request->post());
        }
        $model = new Category();
        return $this->render("list",['model'=>$model]);
    }


    public function actionEdit() {
        $id = \Yii::$app->request->get("id",0);
        $type = (int)\Yii::$app->request->get("type",0);
        $model = Category::modelById($id);
        return $this->render("edit",["model"=>$model,"type"=>$type]);
    }
}